



//dom加载完就运行
$(function(){
	//修整sidebarBox的高度
	//$("#sidebarBox").height($(document).height()-$("#headerBox").height()-31);
	
	var h = $(document).height()-$("#headerBox").height();	
	
	if($.browser.version==8.0)
	{
		h = h-8;
	}
	$("#leftFrame").height(h);
	
	
	switchBtn();
	$('html').css("overflow","hidden");
	$('body').css("overflow","hidden");
	
});

//修正页面窗口重置大小页面高度不适应的问题
$(window).resize(function(){
	
	
	var h = $(window).height()-$("#headerBox").height();	
	
	//alert($(window).height());
	
	if($.browser.version==8.0)
	{
		h = h-8;
	}
	$("#leftFrame").height(h);
	
	var iframeHeight = $("body").height() - $("#headerBox").height()-$("#tabMenuBox").height();
	
	$("#content .iframe").height(iframeHeight);
	
	//$("#leftFrame").height
	//alert('dd')
	});




//左右切换的JS
function switchBtn(){
	var _sidebarBox = $("#sidebarBox"),
	_tabMenuBox = $("#tabMenuBox");

	
	//左侧栏宽度调整
	var $body =$("body"),
	_width = 0,//记录左侧菜单的宽度
	x = 0,//记录鼠标的位置
	bHeight = $body.height(),
	lTop = _sidebarBox.offset().top+_tabMenuBox.height(),
	lHeight = bHeight-lTop,
	LW=0;
	//$(document).bind({mousemove:_mousemove,mouseup:_mouseup});
	
	
	
	var _lineBtn = $("<div class='lineBtn'><div></div></div>").appendTo($body).css("top",lTop).height(lHeight).mousedown(function(e){
			_width = _sidebarBox.width();
			x = e.pageX-_lineBtn.offset().left;
			
			
			 $(document).bind({mousemove:_mousemove,mouseup:_mouseup});
			
		 
			
			
		 
		 
			_lineBtn.height(bHeight).addClass("lineBtn-02").css("top",0);		
			//_lineBtn[0].setCapture();
			_lineBtn.focus();
			 if (document.body.setCapture){
			 	_lineBtn[0].setCapture();
			 }
			 else if(window.captureEvents)
			{
			 	//alert('d')
				//alert(Event.MOUSEMOVE)
			 	window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP); 				
				//_lineBtn.setCapture();
				//_lineBtn[0].addEventListener('mousemove',Event.MOUSEMOVE, true);   
			 }
	        e.preventDefault();                
			return false;
		});
		
	var lineBtnFilter = $('<div>',{'class':'lineBtnFilter'}).appendTo($body);
	
	if($.browser.msie&&$.browser.version==6.0){
		var _iframe = $("<iframe>",{
			"src":"javascript:false",			
			"class":"Liframe",
			"frameborder":0,
			allowtransparency:true,
			scrolling:'no'
		}).appendTo(lineBtnFilter);
		
	}
	
	
	function _mousemove(e){		
	
	
		lineBtnFilter.show();		
		var l = e.pageX-x;
		
		if(l<100){l=100}
		else if(l>800){l=800}
		_lineBtn.offset({left:l,top:0});	
		LW = l;		
		clsSelect(self);
		};
	function _mouseup(e){		
		_lineBtn.removeClass("lineBtn-02").css("top",lTop).height(lHeight);	
		lineBtnFilter.hide();	
		$(window.parent.frames['leftFrame'].document).find("#menuOverflow").css({'width':LW});			//控制菜单的横向滚动条		
		
		if(LW!=0)_sidebarBox.width(LW);	
		if(LW>_width)
		{
			mnBtnResize();
		}
		else
		{
			mnBtnResize2();
		}
		
		
		
		
		 if (document.body.releaseCapture){
		 	_lineBtn[0].releaseCapture();
			
		 }else if(window.releaseEvents)
		 {
		 	window.releaseEvents(Event.MOUSEMOVE|Event.MOUSEUP);
		 }
                        
		$(document).unbind('mousemove',_mousemove).unbind('mouseup',_mouseup);
		//_lineBtn.unbind("mousedown");
				
		}
		
		
		
	//生成打开左侧栏小按钮
	var sBtn_R = $("<div class='sBtn-R'></div>").click(function(){
		_sidebarBox.show();
		$(this).hide();
		_lineBtn.show();
	}).hover(function(){
		$(this).addClass('sBtn-R-02');
	},function(){
		$(this).removeClass('sBtn-R-02');		
	}).prependTo(_tabMenuBox);
	
	//生成关闭右侧栏小按钮
	$("<div class='sBtn'></div>").click(function(){
		_sidebarBox.hide();
		sBtn_R.show();
		_lineBtn.hide();
	}).hover(function(){
		$(this).addClass('sBtn-02');
	},function(){
		$(this).removeClass('sBtn-02');		
	}).appendTo(_sidebarBox);
		
		
	
}







/*
 * 功能：顶部菜单
 * 参数说明：
 * t:菜单标题 [必须]
 * m:左侧菜单url [必须]
 * d:指定高亮显示的菜单 默认是第一个 true 或者 false
 * 调用示例：
 * topMenu([
{t:'系统管理',m:'/html/iframe/leftMenu.shtml'},
{t:'业务管理',m:'/html/iframe/sidebar.shtml?id=1'},
{t:'内容管理',m:'/html/iframe/sidebar.shtml?id=2'},
{t:'配置管理',m:'/html/iframe/sidebar.shtml?id=3'},
{t:'客户管理',m:'/html/iframe/sidebar.shtml?id=4'},
{t:'运营管理',m:'/html/iframe/sidebar.shtml?id=5'},
{t:'专区管理',m:'/html/iframe/sidebar.shtml?id=6'}
])
 * 
 */

function topMenu(options){
	
	var arr = options||[];
	if(arr.length==0)return;
	$(window).load(function(){
		var o=$('#topFrame').contents().find('#topMenu');
		var str_01 = '<ul>';
		var str_02 = '';
		
		//alert(arr[1].d)
		var t = 0;
		$.each(arr,function(i,n){				
			if(!n.d&&n.d==true)
			{
				t=i;
			}
		});
		
		$.each(arr,function(i,n){
			if(i!=t)
			{
				str_02 += "<li onClick=curMenu('topMenu',this) rel="+ n.m + " ><span><label>"+n.t+"</label></span></li>";
			}
			else
			{
				str_02 += "<li class='on' onClick=curMenu('topMenu',this) rel="+ n.m + " ><span><label>"+n.t+"</label></span></li>";
			}
			
		});
		
		
		var str_03 = '</ul>';
		
		o.html(str_01+str_02+str_03);
		
		
		$(window.parent.document).find('#leftFrame')[0].src = arr[t].m;
		
		
		if($.browser.msie&&$.browser.version==6.0)
		{
			o.find('li').hover(function(){
				$(this).addClass("hover");
			},function(){
				 $(this).removeClass("hover");
			});
		}
		
		window.error = null;
	});
	
	//alert(o.attr('id'))
}

 
 
 
 
 
